package com.flowerplus.store.common.data.utils;

import android.support.design.widget.Snackbar;
import android.view.View;

import com.flowerplus.store.R;
import com.flowerplus.store.common.data.utils.ui.ResourcesUtil;

import javax.inject.Inject;

/**
 * Created by z on.
 * Des:
 * Date: 2017/4/10
 */

public class SnackBarUtil {


    private Snackbar mMake;
    private ResourcesUtil mResourcesUtil;

    @Inject
    public SnackBarUtil(ResourcesUtil resourcesUtil) {
        mResourcesUtil = resourcesUtil;
    }


    public void showChatSnackBar(View parentView, String msg, String actionText, View.OnClickListener listener) {
        show(parentView, msg, Snackbar.LENGTH_LONG, mResourcesUtil.getColor(R.color.colorPrimary),
                mResourcesUtil.getColor(R.color.colorAccent), actionText, listener);
    }


    public void show(View parentView, String msg, int duration, int bgColor, int actionColor, String actionText, View.OnClickListener listener) {

        if (mMake == null) {
            mMake = Snackbar.make(parentView, msg, Snackbar.LENGTH_SHORT);
        }
        mMake.getView().setBackgroundColor(bgColor);
        mMake.setText(msg)
                .setDuration(duration)
                .setAction(actionText, listener)
                .setActionTextColor(actionColor)
                .show();

    }

    public static void showStatic(View parentView, String msg) {
        Snackbar.make(parentView, msg, Snackbar.LENGTH_SHORT).setText(msg).show();

    }

    public static void showStatic(View parentView, String msg, String actionText, View.OnClickListener listener) {
        Snackbar.make(parentView, msg, Snackbar.LENGTH_SHORT).setText(msg)
                .setAction(actionText, listener).show();

    }
}
